package com.basv.gifmovieview.slice;

import com.basv.gifmovieview.GifMovieView;
import com.basv.gifmovieview.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.Image;
import ohos.agp.components.LayoutScatter;

/**
 * DecoderSlice
 */
public class MainAbilitySlice extends AbilitySlice {
    private static final String TAG = MainAbilitySlice.class.getName();
    ComponentContainer rootLayout;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        initLayout();
    }

    private void initLayout() {
        rootLayout = (ComponentContainer) LayoutScatter.getInstance(this)
                .parse(ResourceTable.Layout_ability_main, null, false);
        GifMovieView gif = (GifMovieView) rootLayout.findComponentById(ResourceTable.Id_gif);
        gif.setClickedListener(component -> {
            if (gif.isPaused()) {
                gif.resume();
            } else {
                gif.pause();
            }
        });
        GifMovieView gif2 = (GifMovieView) rootLayout.findComponentById(ResourceTable.Id_gif2);
        gif2.setClickedListener(component -> {
            if (gif2.isPaused()) {
                gif2.resume();
            } else {
                gif2.pause();
            }
        });
        GifMovieView gif3 = (GifMovieView) rootLayout.findComponentById(ResourceTable.Id_gif3);
        gif3.setClickedListener(component -> {
            if (gif3.isPaused()) {
                gif3.resume();
            } else {
                gif3.pause();
            }
        });
        GifMovieView gif4 = (GifMovieView) rootLayout.findComponentById(ResourceTable.Id_gif4);
        gif4.setClickedListener(component -> {
            if (gif4.isPaused()) {
                gif4.resume();
            } else {
                gif4.pause();
            }
        });
        GifMovieView gif5 = (GifMovieView) rootLayout.findComponentById(ResourceTable.Id_gif5);
        gif5.setClickedListener(component -> {
            if (gif5.isPaused()) {
                gif5.resume();
            } else {
                gif5.pause();
            }
        });
        super.setUIContent(rootLayout);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    protected void onBackground() {
        super.onBackground();
    }

    @Override
    protected void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    protected void onStop() {
        super.onStop();
    }
}

